package com.example.demo.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class AjaxResult implements Serializable {
    private int code;
    private String msg;
    private Object data;

    //返回成功数据
    public static AjaxResult success(Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setData(data);
        ajaxResult.setMsg("");
        return ajaxResult;
    }
    public static AjaxResult success(Object data,String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(200);
        ajaxResult.setData(data);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    //返回失败数据
    public static AjaxResult fail(Integer code,String msg){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setData("");
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }
    public static AjaxResult fail(Integer code,String msg,Object data){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(code);
        ajaxResult.setData(data);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

}
